/*
package com.rentalHome.util;

import com.rentalHome.domain.User;
import com.rentalHome.repository.UserRepository;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;

*/
/**
 * Created by LeeXyan on 2017/02/27.
 *//*

public class TokenRealm extends AuthorizingRealm {

    @Autowired
    private UserRepository userRepository;

    private User user;
    */
/**
     * 获取授权信息
     * @param principalCollection
     * @return
     *//*

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        return null;
    }

    */
/**
     * 获取认证信息
     * @param token
     * @return
     * @throws AuthenticationException
     *//*

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        String userName = (String) token.getPrincipal();
        String password = String.valueOf((char[]) token.getCredentials());

        User user = userRepository.findByUsername(userName);
        this.user = user;

        if (user == null) {
            throw new UnknownAccountException("用户不存在"); //如果用户不存在
        }

        if (password == null || !password.equals(user.getPassword())) {
            throw new IncorrectCredentialsException("密码错误"); //如果密码错误
        }

        //如果身份认证验证成功，返回一个AuthenticationInfo实现；
        return new SimpleAuthenticationInfo(userName, password, getName());
    }
}
*/
